package com.efounder.view.pop;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.efounder.mobilemall.R;
import com.efounder.view.AmountView;

/**
 * Created by Marcello on 2018/9/26.
 * 立即购买的弹框
 */
@Deprecated
public class BuyNowPopuwindow extends PopupWindow {

    private TextView count;
    private AmountView amountView;
    private TextView tvConfirm;

    public BuyNowPopuwindow(Context context, String price) {
        initView(context, price);
    }

    private void initView(Context context, String price) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView = inflater.inflate(R.layout.pop_window_bugnow, null);
        setContentView(contentView);
        tvConfirm = (TextView) contentView.findViewById(R.id.confirm);
        TextView tvPrice = (TextView) contentView.findViewById(R.id.price1);
        count = (TextView) contentView.findViewById(R.id.count);
        ImageView ivClose = (ImageView) contentView.findViewById(R.id.close);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        tvPrice.setText("￥" + price);

        amountView = (AmountView) contentView.findViewById(R.id.av_amount_view);
        amountView.setCurrentAmount(1);
        amountView.setGoods_storage(1000);
        count.setText(String.format(context.getResources().getString(R.string.mail_number), 999));
        // 设置PopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        // 设置PopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

        int color = context.getResources().getColor(R.color.frame_white_background_color);
        this.setBackgroundDrawable(new ColorDrawable(color));//点击外边可让弹框隐藏
        this.setFocusable(true);
        this.setTouchable(true);
        this.setOutsideTouchable(true);
        // 刷新状态?
        this.update();
        // 设置cPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.pop_anim);
    }

    public void showPopupWindow(View parent) {

        if (!this.isShowing()) {
            this.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        } else {
            this.dismiss();

        }
    }

    //    private void setAlpWindow(float v) {
//        WindowManager.LayoutParams attributes = getWindow().getAttributes();
//        attributes.alpha=v;
//        getWindow().setAttributes(attributes);
//    }
    public TextView getCount() {
        return count;
    }

    public AmountView getAmountView() {
        return amountView;
    }

    public TextView getTvConfirm() {
        return tvConfirm;
    }
}
